<?php


$CONFIG = Zend_Registry::get('config');

set_include_path(get_include_path()
					.PATH_SEPARATOR."../database/models"
					.PATH_SEPARATOR."../database/models/generated"
					//.PATH_SEPARATOR."../database/data/fixtures"
					//.PATH_SEPARATOR."../database/data/sql"
					//.PATH_SEPARATOR."../database/migrations"
					);
					
 require_once('Doctrine/Manager.php');				
					
/*
 * Set super-global data
 */
 
 $dbtype = $CONFIG->database->adapter;
 $host = $CONFIG->database->params->host;
 $user = $CONFIG->database->params->username;
 $pswd = $CONFIG->database->params->password;
 $dbs  = $CONFIG->database->params->dbname;
 
 $Doctrine_Connection = Doctrine_Manager::connection($dbtype.'://'.$user.':'.$pswd.'@'.$host.'/'.$dbs);
 $Doctrine_Connection->setCharset('utf8');
 $Doctrine_Connection->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES,true);// For Table Classes for Models 
 
 $Doctrine_Profiler = new Doctrine_Connection_Profiler();
 $Doctrine_Connection->setListener($Doctrine_Profiler);
//Doctrine::createTablesFromModels('../database/models');
 
 
 $link = mysql_connect($host, $user, $pswd) or die(mysql_error());
 mysql_select_db($dbs, $link) ; 
 mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8', NAMES 'utf8'", $link);
 function getdata($str)
	{
		
		$res = mysql_query($str) or die(mysql_error_report($str));
		return $res;
	}
	
	function mysql_error_report($query)
	{	
		$message = '<pre>';
		$message .= var_export(debug_backtrace(), true);
		$message .= "<br /><br />";
		$message .="POST paramaters:<br /> ";
		$message .= var_export($_POST, true);
		
		
		$message .= "<br /><br />";
		$message .= "GET paramaters: <br />";
		$message .= var_export($_POST, true);
		
		$message .="<br /><br />";
		$message .= "Query String: " . $query . "<br /><br />";
		$message .= "Mysql Error: " . mysql_error();
		$message .="<br /><br />";
		$message .= 'UserId: ' . $_SESSION['MWC_Auth']['UID'];
		$message .= '</pre>';
		
		if(APPLICATION_STATE == 'production') {
			send_mail('Server Error', 'server@fdgfgdf.com', 'test', 'tavvaforu@gmail.com', 'trendopedia SQL Error ' . date("m.d.y"), $message);
			header("Location: server_error.php");
		} elseif (APPLICATION_STATE == 'development' || APPLICATION_STATE == 'staging'){
			echo $message;
		}
	}